package com.server;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.log4j.Logger;
import org.springframework.web.util.WebUtils;

import com.base.BaseController;
import com.dao.UserDao;

@SuppressWarnings("serial")
public class UserLoginServer extends BaseController {
	private static Logger log = Logger.getLogger(UserLoginServer.class);
	
	private UserDao userDao;
	
	public void userlogin(HttpServletRequest request, HttpServletResponse response) throws IOException{
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		if(userDao.userLogin(username, password)){
			//成功放入session中
			WebUtils.setSessionAttribute(request, "username", username);
			response.getWriter().print("ok");
		}else{
			//否则跳转至登录页面
			response.getWriter().print("false");
		}
	}
	
	public void userloginOut(HttpServletRequest request, HttpServletResponse response){
		WebUtils.setSessionAttribute(request, "username", null);
	}
	
	public void userRegiste(HttpServletRequest request, HttpServletResponse response){
		String username = request.getParameter("username");
		String password = request.getParameter("password");
		Boolean succss = userDao.userRegiste(username, password);
	}

	public UserDao getUserDao() {
		return userDao;
	}

	public void setUserDao(UserDao userDao) {
		this.userDao = userDao;
	}
}
